package cn.tedu.cwfw.ser.service.impl;

import cn.tedu.cwfw.ser.mapper.SerClassMapper;
import cn.tedu.cwfw.ser.pojo.dto.SerClassSaveParam;
import cn.tedu.cwfw.ser.pojo.entity.SerClass;
import cn.tedu.cwfw.ser.pojo.vo.SerClassVO;
import cn.tedu.cwfw.ser.service.SerClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class SerClassServiceImpl implements SerClassService {
    @Autowired
    SerClassMapper serClassMapper;

    @Override
    public void insert(SerClassSaveParam serClassSaveParam) {
        log.debug("添加服务分类信息:{}", serClassSaveParam);
        SerClass serClass = new SerClass();
        BeanUtils.copyProperties(serClassSaveParam, serClass);
        serClass.setCreated_time(new Date());
        serClassMapper.insert(serClass);
        log.debug("添加服务分类信息成功");

    }

    @Override
    public List<SerClassVO> selectAll() {
        log.debug("查询所有服务分类信息");
        List<SerClassVO> serClassVOS = serClassMapper.selectAll();
        return serClassVOS;
    }

    @Override
    public SerClassVO findById(Long id) {
        log.debug("根据id查询服务分类信息:{}", id);
        SerClassVO serClassVO = serClassMapper.findById(id);
        return serClassVO;
    }

    @Override
    public void delete(Long id) {
        log.debug("根据id删除服务分类信息:{}", id);
        serClassMapper.delete(id);
        log.debug("根据id删除服务分类信息成功");
    }
}
